{
Author:  Prof1983 prof1983@yandex.ru
Created: 01.03.2009
LastMod: 17.03.2009
}
unit AUIclPanel;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  Classes, Controls, ExtCtrls, Forms, Graphics, StdCtrls,
  ABase, AUI, AUIcl, AUIclFont, AUIclPopupMenu;

type

  { TAUIPanel }

  TAUIPanel = class(TInterfacedObject, IAUIclPanel, IAUIWidget)
  private
    FControl: TPanel;
    FUI: IAUserInterface;
    FFont: IAUIFont;
    FPopupMenu: IAUIPopupMenu;
  protected
    FContains: array of IAUIWidget;
    FRequestSize: TAUISize;
    function GetRequestSizeContains: TAUISize;
  public // IAUIWidget
    function GetRequestSize: TAUISize;
    procedure SetAllocateSize(AWidth, AHeight: Integer); virtual;
    procedure SetPosition(ALeft, ATop: Integer);
    procedure SetRequestSize(Width, Height: Integer);
  public // IAUIContainer
    procedure AddWidget(Widget: IAUIWidget);
  protected // IAUIControl
    function GetEnabled: ABoolean;
    function GetHint: AString;
    function GetText: AString;
    function GetVisible: ABoolean;
    procedure SetEnabled(Value: ABoolean);
    procedure SetHint(const Value: AString);
    procedure SetText(const Value: AString);
    procedure SetVisible(Value: ABoolean);
  protected // IAUIclPanel
    function GetName: AString;
    function Get_Tag: Integer;
    function Get_Left: Integer;
    function Get_Top: Integer;
    function Get_Width: Integer;
    function Get_Height: Integer;
    function Get_Cursor: Integer;
    function Get_HelpType: Integer;
    function Get_HelpKeyword: AString;
    function Get_HelpContext: Integer;
    function Get_Align: Integer;
    function Get_Alignment: Integer;
    function Get_BevelInner: Integer;
    function Get_BevelOuter: Integer;
    function Get_BevelWidth: Integer;
    function Get_BiDiMode: Integer;
    function Get_BorderWidth: Integer;
    function Get_BorderStyle: Integer;
    function Get_Color: Integer;
    function Get_UseDockManager: ABoolean;
    function Get_DockSite: ABoolean;
    function Get_DragCursor: Integer;
    function Get_DragKind: Integer;
    function Get_DragMode: Integer;
    function Get_FullRepaint: ABoolean;
    function Get_Font: IAUIFont;
    procedure SetName(const Value: AString);
    procedure Set_Tag(Value: Integer);
    procedure Set_Left(Value: Integer);
    procedure Set_Top(Value: Integer);
    procedure Set_Width(Value: Integer);
    procedure Set_Height(Value: Integer);
    procedure Set_Cursor(Value: Integer);
    procedure Set_HelpType(Value: Integer);
    procedure Set_HelpKeyword(const Value: AString);
    procedure Set_HelpContext(Value: Integer);
    procedure Set_Align(Value: Integer);
    procedure Set_Alignment(Value: Integer);
    //function Get_AutoSize: Integer;
    //procedure Set_AutoSize(Value: Integer);
    procedure Set_BevelInner(Value: Integer);
    procedure Set_BevelOuter(Value: Integer);
    procedure Set_BevelWidth(Value: Integer);
    procedure Set_BiDiMode(Value: Integer);
    procedure Set_BorderWidth(Value: Integer);
    procedure Set_BorderStyle(Value: Integer);
    procedure Set_Color(Value: Integer);
    //function Get_Ctl3D: Integer;
    //procedure Set_Ctl3D(Value: Integer);
    procedure Set_UseDockManager(Value: ABoolean);
    procedure Set_DockSite(Value: ABoolean);
    procedure Set_DragCursor(Value: Integer);
    procedure Set_DragKind(Value: Integer);
    procedure Set_DragMode(Value: Integer);
    procedure Set_FullRepaint(Value: ABoolean);
    //function Get_Locked: Integer;
    //procedure Set_Locked(Value: Integer);
    function Get_ParentBiDiMode: ABoolean;
    procedure Set_ParentBiDiMode(Value: ABoolean);
    //function Get_ParentBackground: Integer;
    //procedure Set_ParentBackground(Value: Integer);
    {function Get_ParentColor: ABoolean;
    procedure Set_ParentColor(Value: ABoolean);
    function Get_ParentCtl3D: ABoolean;
    procedure Set_ParentCtl3D(Value: ABoolean);
    function Get_ParentFont: ABoolean;
    procedure Set_ParentFont(Value: ABoolean);
    function Get_ParentShowHint: ABoolean;
    procedure Set_ParentShowHint(Value: ABoolean);}
    function Get_PopupMenu: IAUIPopupMenu;
    function Get_ShowHint: ABoolean;
    procedure Set_ShowHint(Value: ABoolean);
    function Get_TabOrder: Integer;
    procedure Set_TabOrder(Value: Integer);
    function Get_TabStop: ABoolean;
    procedure Set_TabStop(Value: ABoolean);
  public
    constructor Create(UI: IAUserInterface; Control: TPanel);
  end;

implementation

{ TAUIPanel }

procedure TAUIPanel.AddWidget(Widget: IAUIWidget);
var
  Control: TControl;
  I: Integer;
begin
  if not(Assigned(Widget)) then Exit;
  Control := FUI.GetWidgetControl(Widget);
  if not(Assigned(Control)) then Exit;
  if not(Control is TWinControl) then Exit;
  Control.Parent := FControl;

  I := Length(FContains);
  SetLength(FContains, I + 1);
  FContains[I] := Widget;
end;

constructor TAUIPanel.Create(UI: IAUserInterface; Control: TPanel);
begin
  FUI := UI;
  UI.RegisterWidgetControl(Self, Control);
  FControl := Control;
end;

function TAUIPanel.GetRequestSize: TAUISize;
begin
  Result := GetRequestSizeContains();
  if (Result.Height < FRequestSize.Height) then
    Result.Height := FRequestSize.Height;
  if (Result.Width < FRequestSize.Width) then
    Result.Width := FRequestSize.Width;
end;

function TAUIPanel.GetRequestSizeContains: TAUISize;
var
  I: Integer;
  R: TAUISize;
begin
  Result.Height := 0;
  Result.Width := 0;
  for I := 0 to High(FContains) do
  begin
    R := FContains[I].GetRequestSize();
    Result.Height := Result.Height + R.Height;
    Result.Width := Result.Width + R.Width;
  end;
end;

function TAUIPanel.Get_Cursor: Integer;
begin
  Result := FControl.Cursor;
end;

function TAUIPanel.Get_Height: Integer;
begin
  Result := FControl.Height;
end;

function TAUIPanel.Get_Left: Integer;
begin
  Result := FControl.Left;
end;

function TAUIPanel.GetName: AString;
begin
  Result := FControl.Name;
end;

function TAUIPanel.Get_Tag: Integer;
begin
  Result := FControl.Tag;
end;

function TAUIPanel.Get_Top: Integer;
begin
  Result := FControl.Top;
end;

function TAUIPanel.Get_Width: Integer;
begin
  Result := FControl.Width;
end;

procedure TAUIPanel.SetAllocateSize(AWidth, AHeight: Integer);
{var
  I: Integer;
  RSize: TAUISize;
  CSize: TAUISize;
  DeltaX: Integer;
  DeltaY: Integer;
  DX: Integer;
  DY: Integer;
  MaxX: Integer;
  MaxX_Index: Integer;
  MaxY: Integer;
  MaxY_Index: Integer;
  SumX: Integer;
  SumY: Integer;}
begin
  FControl.Height := AHeight;
  FControl.Width := AWidth;
  {
  RSize := GetRequestSizeContains();
  DeltaX := AWidth - RSize.Width;
  DeltaY := AHeight - RSize.Height;
  MaxX := 0;
  MaxY := 0;
  SumX := 0;
  SumY := 0;
  for I := 0 to High(FContains) do
  begin
    CSize := FContains[I].GetRequestSize();
    if (DeltaX > 0) then
    begin
      DX := (DeltaX * CSize.Width) div RSize.Width;
      CSize.Width := CSize.Width + DX;
      SumX := SumX + DX;
    end;
    if (DeltaY > 0) then
    begin
      DY := (DeltaY * CSize.Height) div RSize.Height;
      CSize.Height := CSize.Height + DY;
      SumY := SumY + DY;
    end;
    FContains[I].SetAllocateSize(CSize.Width, CSize.Height);
    // ...
  end;
  }
end;

procedure TAUIPanel.SetPosition(ALeft, ATop: Integer);
begin
  FControl.Left := ALeft;
  FControl.Top := ATop;
end;

procedure TAUIPanel.SetRequestSize(Width, Height: Integer);
begin
  FRequestSize.Width := Width;
  FRequestSize.Height := Height;
end;

procedure TAUIPanel.Set_Cursor(Value: Integer);
begin
  FControl.Cursor := Value;
end;

procedure TAUIPanel.Set_Height(Value: Integer);
begin
  FControl.Height := Value;
end;

procedure TAUIPanel.Set_Left(Value: Integer);
begin
  FControl.Left := Value;
end;

procedure TAUIPanel.SetName(const Value: AString);
begin
  FControl.Name := Value;
end;

procedure TAUIPanel.Set_Tag(Value: Integer);
begin
  FControl.Tag := Value;
end;

procedure TAUIPanel.Set_Top(Value: Integer);
begin
  FControl.Top := Value;
end;

procedure TAUIPanel.Set_Width(Value: Integer);
begin
  FControl.Width := Value;
end;


function TAUIPanel.GetHint: AString;
begin
  Result := FControl.Hint;
end;

procedure TAUIPanel.SetHint(const Value: AString);
begin
  FControl.Hint := Value;
end;

function TAUIPanel.Get_HelpType: Integer;
begin
  Result := Integer(FControl.HelpType);
end;

procedure TAUIPanel.Set_HelpType(Value: Integer);
begin
  FControl.HelpType := THelpType(Value);
end;

function TAUIPanel.Get_HelpKeyword: AString;
begin
  Result := FControl.HelpKeyword;
end;

procedure TAUIPanel.Set_HelpKeyword(const Value: AString);
begin
  FControl.HelpKeyword := Value;
end;

function TAUIPanel.Get_HelpContext: Integer;
begin
  Result := FControl.HelpContext;
end;

procedure TAUIPanel.Set_HelpContext(Value: Integer);
begin
  FControl.HelpContext := Value;
end;

function TAUIPanel.Get_Align: Integer;
begin
  Result := Integer(FControl.Align);
  {if (FControl.Align = alNone) then Result := 0;
  if (FControl.Align = alTop) then Result := 1;
  if (FControl.Align = alBottom) then Result := 2;
  if (FControl.Align = alLeft) then Result := 3;
  if (FControl.Align = alRight) then Result := 4;
  if (FControl.Align = alClient) then Result := 5;
  if (FControl.Align = alCustom) then Result := 6;}
end;

procedure TAUIPanel.Set_Align(Value: Integer);
begin
  FControl.Align := TAlign(Value);
  {if (Value = 0) then FControl.Align := alNone;
  if (Value = 1) then FControl.Align := alTop;
  if (Value = 2) then FControl.Align := alBottom;
  if (Value = 3) then FControl.Align := alLeft;
  if (Value = 4) then FControl.Align := alRight;
  if (Value = 5) then FControl.Align := alClient;
  if (Value = 6) then FControl.Align := alCustom;}
end;

function TAUIPanel.Get_Alignment: Integer;
begin
  Result := Integer(FControl.Alignment);
end;

procedure TAUIPanel.Set_Alignment(Value: Integer);
begin
  FControl.Alignment := TAlignment(Value);
end;

{function TAUIPanel.Get_AutoSize: Integer;
begin
  if (FControl.AutoSize = False) then Result := 0;
  if (FControl.AutoSize = True) then Result := 1;
end;}

{procedure TAUIPanel.Set_AutoSize(Value: Integer);
begin
  if (Value = 0) then FControl.AutoSize := False;
  if (Value = 1) then FControl.AutoSize := True;
end;}

function TAUIPanel.Get_BevelInner: Integer;
begin
  Result := Integer(FControl.BevelInner);
end;

procedure TAUIPanel.Set_BevelInner(Value: Integer);
begin
  FControl.BevelInner := TBevelCut(bvNone);
end;

function TAUIPanel.Get_BevelOuter: Integer;
begin
  Result := Integer(FControl.BevelOuter);
end;

procedure TAUIPanel.Set_BevelOuter(Value: Integer);
begin
  FControl.BevelOuter := TBevelCut(Value);
end;

function TAUIPanel.Get_BevelWidth: Integer;
begin
  Result := FControl.BevelWidth;
end;

procedure TAUIPanel.Set_BevelWidth(Value: Integer);
begin
  FControl.BevelWidth := Value;
end;

function TAUIPanel.Get_BiDiMode: Integer;
begin
  Result := Integer(FControl.BiDiMode);
end;

procedure TAUIPanel.Set_BiDiMode(Value: Integer);
begin
  FControl.BiDiMode := TBiDiMode(Value);
end;

function TAUIPanel.Get_BorderWidth: Integer;
begin
  Result := FControl.BorderWidth;
end;

procedure TAUIPanel.Set_BorderWidth(Value: Integer);
begin
  FControl.BorderWidth := Value;
end;

function TAUIPanel.Get_BorderStyle: Integer;
begin
  Result := Integer(FControl.BorderStyle);
end;

procedure TAUIPanel.Set_BorderStyle(Value: Integer);
begin
  FControl.BorderStyle := TBorderStyle(Value);
end;

function TAUIPanel.Get_Color: Integer;
begin
  Result := FControl.Color;
end;

procedure TAUIPanel.Set_Color(Value: Integer);
begin
  FControl.Color := Value;
end;

{function TAUIPanel.Get_Ctl3D: Integer;
begin
    if (FControl.Ctl3D = False) then Result := 0;
    if (FControl.Ctl3D = True) then Result := 1;
end;}

{procedure TAUIPanel.Set_Ctl3D(Value: Integer);
begin
   if (Value = 0) then FControl.Ctl3D := False;
   if (Value = 1) then FControl.Ctl3D := True;
end;}

function TAUIPanel.Get_UseDockManager: ABoolean;
begin
  Result := FControl.UseDockManager;
end;

procedure TAUIPanel.Set_UseDockManager(Value: ABoolean);
begin
  FControl.UseDockManager := Value;
end;

function TAUIPanel.Get_DockSite: ABoolean;
begin
  Result := FControl.DockSite;
end;

procedure TAUIPanel.Set_DockSite(Value: ABoolean);
begin
  FControl.DockSite := Value;
end;

function TAUIPanel.Get_DragCursor: Integer;
begin
  Result := FControl.DragCursor;
end;

procedure TAUIPanel.Set_DragCursor(Value: Integer);
begin
  FControl.DragCursor := Value;
end;

function TAUIPanel.Get_DragKind: Integer;
begin
  {$IFNDEF UNIX}
  Result := Integer(FControl.DragKind);
  {$ELSE}
  Result := 0;
  {$ENDIF}
end;

procedure TAUIPanel.Set_DragKind(Value: Integer);
begin
  {$IFNDEF UNIX}
  FControl.DragKind := TDragKind(Value);
  {$ENDIF}
end;

function TAUIPanel.Get_DragMode: Integer;
begin
  Result := Integer(FControl.DragMode);
end;

procedure TAUIPanel.Set_DragMode(Value: Integer);
begin
  FControl.DragMode := TDragMode(Value);
end;

function TAUIPanel.GetEnabled: ABoolean;
begin
  Result := FControl.Enabled;
end;

procedure TAUIPanel.SetEnabled(Value: ABoolean);
begin
  FControl.Enabled := Value;
end;

function TAUIPanel.Get_FullRepaint: ABoolean;
begin
  Result := FControl.FullRepaint;
end;

procedure TAUIPanel.Set_FullRepaint(Value: ABoolean);
begin
  FControl.FullRepaint := Value;
end;

function TAUIPanel.Get_Font: IAUIFont;
begin
  if not(Assigned(FFont)) then
    FFont := TAUIFont.Create(FControl.Font);
  Result := FFont;
end;

{function TAUIPanel.Get_Locked: Integer;
begin
    if (FControl.Locked = False) then Result := 0;
    if (FControl.Locked = True) then Result := 1;
end;}

{procedure TAUIPanel.Set_Locked(Value: Integer);
begin
   if (Value = 0) then FControl.Locked := False;
   if (Value = 1) then FControl.Locked := True;
end;}

function TAUIPanel.Get_ParentBiDiMode: ABoolean;
begin
  Result := FControl.ParentBiDiMode;
end;

procedure TAUIPanel.Set_ParentBiDiMode(Value: ABoolean);
begin
  FControl.ParentBiDiMode := Value;
end;

(*function TAUIPanel.Get_ParentBackground: Integer;
begin
  {$IFNDEF UNIX}
  if (FControl.ParentBackground = False) then Result := 0;
  if (FControl.ParentBackground = True) then Result := 1;
  {$ENDIF}
end;

procedure TAUIPanel.Set_ParentBackground(Value: Integer);
begin
  {$IFNDEF UNIX}
  if (Value = 0) then FControl.ParentBackground := False;
  if (Value = 1) then FControl.ParentBackground := True;
  {$ENDIF}
end;*)

{function TAUIPanel.Get_ParentColor: ABoolean;
begin
  Result := FControl.ParentColor;
end;

procedure TAUIPanel.Set_ParentColor(Value: ABoolean);
begin
  FControl.ParentColor := Value;
end;

function TAUIPanel.Get_ParentCtl3D: ABoolean;
begin
  Result := FControl.ParentCtl3D;
end;

procedure TAUIPanel.Set_ParentCtl3D(Value: ABoolean);
begin
  FControl.ParentCtl3D := Value;
end;

function TAUIPanel.Get_ParentFont: ABoolean;
begin
  Result := FControl.ParentFont;
end;

procedure TAUIPanel.Set_ParentFont(Value: ABoolean);
begin
  FControl.ParentFont := Value;
end;

function TAUIPanel.Get_ParentShowHint: ABoolean;
begin
  Result := FControl.ParentShowHint;
end;

procedure TAUIPanel.Set_ParentShowHint(Value: ABoolean);
begin
  FControl.ParentShowHint := Value;
end;}

function TAUIPanel.Get_PopupMenu: IAUIPopupMenu;
begin
  if not(Assigned(FPopupMenu)) then
    FPopupMenu := TAUIPopupMenu.Create(FUI, FControl.PopupMenu);
  Result := FPopupMenu;
end;

function TAUIPanel.Get_ShowHint: ABoolean;
begin
  Result := FControl.ShowHint;
end;

procedure TAUIPanel.Set_ShowHint(Value: ABoolean);
begin
  FControl.ShowHint := Value;
end;

function TAUIPanel.Get_TabOrder: Integer;
begin
  Result := FControl.TabOrder;
end;

procedure TAUIPanel.Set_TabOrder(Value: Integer);
begin
  FControl.TabOrder := Value;
end;

function TAUIPanel.Get_TabStop: ABoolean;
begin
  Result := FControl.TabStop;
end;

procedure TAUIPanel.Set_TabStop(Value: ABoolean);
begin
  FControl.TabStop := Value;
end;

function TAUIPanel.GetVisible: ABoolean;
begin
  Result := FControl.Visible;
end;

procedure TAUIPanel.SetVisible(Value: ABoolean);
begin
  FControl.Visible := Value;
end;

function TAUIPanel.GetText: AString;
begin
  Result := FControl.Caption;
end;

procedure TAUIPanel.SetText(const Value: AString);
begin
  FControl.Caption := Value;
end;

end.
